#ifndef BUTTON_H
#define BUTTON_H

#include <easyx/graphics.h>
#include <string>
/*
"*******************************************************"
"*                 COPYRIGHT STATEMENT                 *"
"*           THIS HEADER IS CODED BY ZEPHYRBD!         *"
"*This  header is open - sourced under the MIT License.*"
"*       Copyright 2018-2025 Minecraft ZBD Studio.     *"
"*******************************************************"
*/
class Button 
{
private:
	int x,y,w,h;
	COLORREF curColor = RGB(225, 225, 225);//按钮当前颜色
	COLORREF fontcolor = BLACK;
	COLORREF inColor = RGB(229, 241, 251);//鼠标在按钮上颜色
	COLORREF outColor = RGB(225, 225, 225);//鼠标不在按钮上颜色
	std::string text;
	
public:
	Button(int _x,int _y,int _w,int _h,std::string _text ) 
	: x(_x),y(_y),w(_w),h(_h),text(_text){}
	
	void createButton()
	{
		setfillcolor(curColor);
		setlinecolor(RGB(173, 173, 173));
		fillrectangle(x, y, x + w, y + h);
		
		settextcolor(fontcolor);
		setbkmode(TRANSPARENT);
		settextstyle(20, 0, "MiSans");
		
		int textX = x + (w - textwidth(text.c_str())) / 2;
		int textY = y + (h - textheight(text.c_str())) / 2;
		outtextxy(textX,textY,text.c_str());
	}
	
	bool isInButton(ExMessage m)
	{
		if(m.x>x&&m.x<x+w&&m.y>y&&m.y<y+h)
		{
			curColor = inColor;
			return true;
		}
		curColor = outColor;
		return false;
	}
};

#endif
